package com.alibaba.travel.article.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.travel.article.entity.ArticleTagEntity;
import com.alibaba.travel.article.service.ArticleTagService;
import com.alibaba.travel.common.utils.PageUtils;
import com.alibaba.travel.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;




/**
 * 文章标签表
 *
 * @author wherezy
 * @email wherezy@tom.com
 * @date 2023-02-23 15:08:54
 */
@Api(tags = {"文章标签表ArticleTagController"})
@RestController
@RequestMapping("article/articletag")
public class ArticleTagController {
    @Autowired
    private ArticleTagService articleTagService;

    @ApiOperation(value="获取所有的标签", notes="")
    @PostMapping("/all")
    public R getAll(){
        List<ArticleTagEntity> list = articleTagService.list();
        return R.ok().put("list", list);
    }

    /**
     * 列表
     */
    @ApiOperation(value="分页获取信息", notes="k-v map形式封装分页参数")
    @PostMapping("/list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = articleTagService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value="获取信息")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ArticleTagEntity articleTag = articleTagService.getById(id);

        return R.ok().put("articleTag", articleTag);
    }

    /**
     * 保存
     */
    @ApiOperation(value="保存")
    @PostMapping("/save")
    public R save(@RequestBody ArticleTagEntity articleTag){
		articleTagService.save(articleTag);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改")
    @PostMapping("/update")
    public R update(@RequestBody ArticleTagEntity articleTag){
		articleTagService.updateById(articleTag);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		articleTagService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
